<?php



namespace app\controller\api\store\product;

use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\store\StoreCategoryRepository as repository;

class StoreCategory extends BaseController
{
    protected $repository;

    /**
     * ProductCategory constructor.
     * @param App $app
     * @param repository $repository
     */
    public function __construct(App $app, repository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }

    /**
     * @Author:Qinii
     * @Date: 2020/5/27
     * @return mixed
     */
    public function lst()
    {
        $category = \app\common\model\store\StoreCategory::getDB()->where('level', 2)
            ->where('is_show', 1)->where('mer_id', 0)->order('sort', 'desc')->select();
        $brand = \app\common\model\system\merchant\Merchant::getDB()
            ->where('status', 1)->where('is_del', 0)->where('mer_state', 1)
            ->field('mer_id,mer_avatar,mer_name,mer_info')
            ->order('sort', 'desc')->select();
        $brand_t = \app\common\model\system\merchant\Merchant::getDB()
            ->where('status', 1)->where('is_del', 0)->where('mer_state', 1)->where('is_best', 1)
            ->field('mer_id,mer_avatar,mer_name,mer_info')
            ->order('sort', 'desc')->limit(3)->select();
        $cate_top_img = systemConfig('cate_top_img');
        $cate_top_img_br = systemConfig('cate_top_img_br');
        return app('json')->success(compact('category', 'brand', 'brand_t', 'cate_top_img', 'cate_top_img_br'));
    }

    public function children()
    {
        $pid = (int)$this->request->param('pid');
        return app('json')->success($this->repository->children($pid));
    }
}